package com.asc.mywriter.controller;

import com.asc.mywriter.bean.User;
import com.asc.mywriter.mapper.UserMapper;
import com.asc.mywriter.serciceImpl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

@Controller
public class UserController {

    @Autowired
    UserServiceImpl userService;

    @PostMapping(value = "/user")
    public String login(@RequestParam("userName") String userName, @RequestParam("passWord") String passWord, Map<String,Object> map, HttpSession session){
        User user =userService.findUser(userName,passWord);
        if(!ObjectUtils.isEmpty(user)){
            session.setAttribute("userId",user.getId());
            session.setAttribute("userName",user.getUserName());

            return "redirect:index.html";
        }else{
            map.put("msg","密码用户名错误！");
            return "login";
        }
    }
}
